<template>
  <div ref="lineRef" id="line" :style="{ height, width }" />
</template>

<script lang="ts" setup>
import * as echarts from 'echarts';
import { onBeforeMount, onBeforeUnmount, onMounted, ref } from 'vue';
const props = defineProps({
  width: {
    type: String,
    default: '100%',
  },
  height: {
    type: String,
    default: '200px',
  },
  chartData: {
    type: Object,
    default: () => {
      return {};
    },
  },
});
const lineRef = ref<any>(null);
const lineData = ref<any>([]);

onMounted(() => {
  lineData.value = props.chartData;
  initChart();
});
const initChart = () => {
  const myChart = echarts.init(lineRef.value);
  myChart.setOption(optionConfig(), true);
};

const optionConfig = () => {
  const option = {
    tooltip: {
      trigger: 'axis',
    },
    grid: {
      left: '4%',
      bottom: '3%',
      containLabel: true,
    },
    xAxis: {
      name: '推算边界',
      type: 'category',
      boundaryGap: true,
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      axisTick: {
        // 刻度线控制在柱状图居中
        alignWithLabel: true,
      },
    },
    yAxis: {
      name: '评估指标',
      type: 'value',
      scale: true,
      nameTextStyle: {
        color: '#000',
        nameLocation: 'start',
      },
    },
    series: [
      {
        data: [820, 932, 901, 934, 190, 130, 320],
        type: 'line',
        smooth: true,
      },
    ],
  };
  return option;
};
</script>
<style lang="scss" scoped>
.line-echarts {
}
</style>
